<?php

/**
 * This is the model class for table "zy_potential_customers".
 *
 * The followings are the available columns in table 'zy_potential_customers':
 * @property integer $potential_customers_id
 * @property integer $potential_customers_list_id
 * @property string $first_name
 * @property string $last_name
 * @property string $gender
 * @property string $mobile
 * @property string $email
 * @property string $address
 * @property string $post_code
 * @property string $customer_detail1
 * @property string $customer_detail2
 * @property string $customer_detail3
 * @property string $customer_detail4
 * @property string $customer_detail5
 * @property string $customer_detail6
 * @property string $customer_detail7
 * @property string $customer_detail8
 * @property string $customer_detail9
 * @property string $customer_detail10
 *
 * The followings are the available model relations:
 * @property ZyPotentialCustomersList $potentialCustomersList
 */
class PotentialCustomers extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PotentialCustomers the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_potential_customers';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('potential_customers_list_id', 'numerical', 'integerOnly'=>true),
			array('first_name, last_name, gender', 'length', 'max'=>50),
			array('mobile, email, address,post_code, customer_detail1, customer_detail2, customer_detail3, customer_detail4, customer_detail5, customer_detail6, customer_detail7, customer_detail8, customer_detail9, customer_detail10,update_user,update_time', 'length', 'max'=>255),
			array('email','email'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('potential_customers_id, potential_customers_list_id, first_name, last_name, gender, mobile, email, address,post_code, customer_detail1, customer_detail2, customer_detail3, customer_detail4, customer_detail5, customer_detail6, customer_detail7, customer_detail8, customer_detail9, customer_detail10,mark,update_user,update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'potentialCustomersList' => array(self::BELONGS_TO, 'ZyPotentialCustomersList', 'potential_customers_list_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'potential_customers_id' => Yii::t('base','Potential Customers'),
			'potential_customers_list_id' =>Yii::t('base','Potential Customers List'),
			'first_name' => Yii::t('base','First Name'),
			'last_name' => Yii::t('base','Last Name'),
			'gender' => Yii::t('base','Title'),
			'mobile' => Yii::t('base','Mobile'),
			'email' => Yii::t('base','Email'),
			'address' => Yii::t('base','Address'),
			//'status' => Yii::t('base','Status'),
			'post_code' => Yii::t('base','Post Code'),
			'customer_detail1' => Yii::t('base','Customer Detail').'1',
			'customer_detail2' =>Yii::t('base', 'Customer Detail').'2',
			'customer_detail3' => Yii::t('base','Customer Detail').'3',
			'customer_detail4' => Yii::t('base','Customer Detail').'4',
			'customer_detail5' => Yii::t('base','Customer Detail').'5',
			'customer_detail6' => Yii::t('base','Customer Detail').'6',
			'customer_detail7' => Yii::t('base','Customer Detail').'7',
			'customer_detail8' => Yii::t('base','Customer Detail').'8',
			'customer_detail9' => Yii::t('base','Customer Detail').'9',
			'customer_detail10' => Yii::t('base','Customer Detail').'10',
			'mark'=>Yii::t('base','Mark'),
			'update_user'=>Yii::t('base','Update User'),
			'update_time'=>Yii::t('base','Update Time'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('potential_customers_id',$this->potential_customers_id);
		$criteria->compare('potential_customers_list_id',$this->potential_customers_list_id);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('address',$this->address,true);
		//$criteria->compare('status',$this->status,true);
		$criteria->compare('post_code',$this->post_code,true);
		$criteria->compare('customer_detail1',$this->customer_detail1,true);
		$criteria->compare('customer_detail2',$this->customer_detail2,true);
		$criteria->compare('customer_detail3',$this->customer_detail3,true);
		$criteria->compare('customer_detail4',$this->customer_detail4,true);
		$criteria->compare('customer_detail5',$this->customer_detail5,true);
		$criteria->compare('customer_detail6',$this->customer_detail6,true);
		$criteria->compare('customer_detail7',$this->customer_detail7,true);
		$criteria->compare('customer_detail8',$this->customer_detail8,true);
		$criteria->compare('customer_detail9',$this->customer_detail9,true);
		$criteria->compare('customer_detail10',$this->customer_detail10,true);
		$criteria->compare('mark',$this->mark,true);
		$criteria->compare('update_user',$this->update_user,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	//通过customersList id得到改ID的名字
	public function getCustomersListName($potential_customers_list_id)
	{
	$rs=PotentialCustomersList::model()->find('potential_customers_list_id=:potential_customers_list_id',array(':potential_customers_list_id'=>$potential_customers_list_id));
		return $rs->potential_customers_list_name;
	}
}